package cn.regexp.service.impl;

import cn.regexp.domain.ShopCanteen;
import cn.regexp.domain.ShopWindow;
import cn.regexp.mapper.CanteenMapper;
import cn.regexp.service.ICanteenService;
import cn.regexp.service.IWindowService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CanteenServiceImpl extends ServiceImpl<CanteenMapper, ShopCanteen> implements ICanteenService {

    @Autowired
    private IWindowService windowService;

    @Override
    public List<ShopCanteen> queryCanteen() {
        // 查询所有餐厅
        List<ShopCanteen> canteenList = super.list();
        QueryWrapper<ShopWindow> wrapper = new QueryWrapper<>();;
        List<ShopWindow> shopWindowList;
        for (ShopCanteen shopCanteen : canteenList) {
            // 清除 wrapper 中已有的条件
            wrapper.clear();
            // 添加餐厅 id 作为条件
            wrapper.eq("canteen_id", shopCanteen.getId());
            shopWindowList = windowService.list(wrapper);
            // 查询餐厅对应的所有窗口
            shopCanteen.setShopWindowList(shopWindowList);
        }
        return canteenList;
    }
}
